﻿#include "pattern.h"
#include <locale.h>

//cmd line -debug open debug     
void main(int argc, char **argv)
{
	DB_DEBUG=1;
 DB_BOOL  result ;
 RECORD  outdata;
 int total=10;
// char*  name[]={"2014052"};
  char*  name[]={"2014029","2014031",
 						"2011082","2014032","2014035","2014037","general",
 						"2014038","2006027","2014052"
 						};

	 int indicator=0;

 printf ("%s\n", setlocale(LC_ALL, ""));
 wchar_t* tips = L"开始预测...";
     char **CURRENT_RECORDS;//所有记录
     int CURRENT_ROWS;
     int CURRENT_COLS;
     sqlite3*  CURRENT_DB; 	
uint64_t now= getCurrentTimestamp();
char *lastterm="SELECT trim(term) as term,red1,red2,red3,red4,red5,red6,blue FROM _DBHISTORY order by term desc limit 1 ";         			                                         
query(CURRENT_DB,lastterm,&CURRENT_RECORDS,&CURRENT_ROWS,&CURRENT_COLS);
 if(DB_DEBUG)printf("current_rows:%d,current_cols:%d\n",	CURRENT_ROWS,CURRENT_COLS);
 	
RECORD* result2 = rowsToRecords(CURRENT_RECORDS, CURRENT_ROWS, CURRENT_COLS);

if(result2!=NULL)
   {
printf("%ls,%s\n",tips,result2[0].term);
//start predication.................
for(int i=0;i<total;i++)
{
	result=HandlePattern(result2[0],name[i],&outdata);
			 if(result==MATCH) 
			{
			printRecord(outdata);	
			  }else
		{
  printf("%s not match,skiped...\n",name[i]);			
			continue;
			}	  	
	printf("match %s pattern pre %s\n",name[i],formatRecord(outdata));
}
free(result2);
sqlite3_free_table(CURRENT_RECORDS);
   }

uint64_t end= getCurrentTimestamp();   
uint64_t diff=end-now;
printf("%" PRIu64 " microsecond %.3f seconds consumed \n",diff,(float)diff/1000);
}
